var text = 'http://baidu.com/';
var postUrl = './post.png';
var imgId = '#result'
var qrcode = new QRCode(document.getElementById("qrcode"), {
    text: text,
    width : 180,
    height : 180
})
function createPost(text, postUrl,imgId) {
    // var qrcode = new QRious({
    //     element: document.getElementById("qrcode"),       
    //     value: text,
    //     level: 'H',
    //     size : 180,
    //     // padding: 5,
    // })    

    var eleImgCover = document.querySelector('#qrcode img')
    var getImg = function(url, callback) {
        var canvas = document.createElement('canvas');
        var width = 720;
        var height = 1120;
        canvas.width = width;
        canvas.height = height;
        var context = canvas.getContext('2d');
        var imgUpload = new Image();
        imgUpload.onload = function () {
            context.drawImage(imgUpload, 0, 0, width, height);
            context.drawImage(eleImgCover, (width - 180)/2, height - 240);
            callback(canvas.toDataURL('image/png'));
        };
        imgUpload.src = url;    
    }
    getImg(postUrl, function(data) {
        document.querySelector(imgId).src = data
    })
}
createPost(text, postUrl,imgId)